﻿using System;
using Ue.CQRS.Samples.DataContracts;
using Ue.CQRS.Samples.Repositories;
using Ue.CQRS.Samples.Models;

namespace Ue.CQRS.Samples.Services.CommandService
{
    public class CommandService : ICommandService
    {
        public IRepository<Book> bookRepository;

        public CommandService(IRepository<Book> bookRepository)
        {
            this.bookRepository = bookRepository;
        }

        public void BookAddOrUpdate(BookContract bookContract)
        {
            var key=bookContract.Id.Value;

            if (!this.bookRepository.ContainsKey(key))
            {
                Book.Create(bookContract);
            }
            else
            {
                this.bookRepository[key].Update(bookContract);
            }
        }
    }
}
